package com.ecom.common.dao;

import com.ecom.common.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by jimmy on 7/31/14.
 */
@Repository
public class OrderDao {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public List<ShipMethod> getShipMethods() {

        String sqlString = "select mid, name, charges from ship_method";

        List<ShipMethod> methods = jdbcTemplate.query(sqlString, new RowMapper<ShipMethod>() {
            public ShipMethod mapRow(ResultSet rs, int rowNum)
                    throws SQLException {
                ShipMethod method = new ShipMethod();
                method.setMid(rs.getInt(1));
                method.setMethodName(rs.getString(2));
                method.setCharge(rs.getDouble(3));
                return method;
            }
        });

        return methods;
    }

    public void insertAddress(Address address) {

    }

    public void insertPayOption(PayOption payOption) {

    }

    public void insertUserHasPayOption(String userEmail, int accountNumber) {

    }

    public void insertOrder(List<Product> products, String confirmationNum, String userEmail, int mid, int accountNumber) {

    }
}
